import {getObj} from '@/views/client-manage/api/clientprovider'
import {getByclientProviderId} from '@/views/client-manage/api/clientproviderlinkinfo'
import pager from '@/assets/vue-mixin/pager'
import uploadMedia from '@/components/upload-media.vue'
import contractInfo from '@/views/client-manage/components/contract-info.vue'
import projectInfo from '@/views/client-manage/components/project-info.vue'
import paymentRecordProvide from '@/views/client-manage/components/payment-RecordProvid.vue'
import debtRecordProvide from '@/views/client-manage/components/debt-RecordProvid.vue'
import {mapState} from "vuex";

export default {
    name: 'look',
    computed: {
        ...mapState({
            provider_type: state => {
                let data = state.dict.find(item => item.type === "provider_type") || {}
                let list = data.children || []
                return data.children || []
            },
        }),
    },
    components: {
        uploadMedia,
        contractInfo,
        paymentRecordProvide,
        debtRecordProvide,
        projectInfo
    },
    created(){
        const loading = this.$loading({
            lock: true,
            text: '数据加载中'
        });
        //qh+:获取路径上传过来的ID
        this.supplierId = this.$route.query.id
        this.busId=this.supplierId
        console.log("id=============>"+this.supplierId)
        //通过id获取项目信息
        getObj(this.supplierId).then( rep => {
            this.propForm = rep.data.data
            if(this.propForm.clientProviderType==0){
                this.clientProviderTypeMean=this.provider_type[0].label
            }else  if(this.propForm.clientProviderType==1){
                this.clientProviderTypeMean=this.provider_type[1].label
            }else  if(this.propForm.clientProviderType==2){
                this.clientProviderTypeMean=this.provider_type[2].label
            }else  if(this.propForm.clientProviderType==3){
                this.clientProviderTypeMean=this.provider_type[3].label
            }else  if(this.propForm.clientProviderType==4){
                this.clientProviderTypeMean=this.provider_type[4].label
            }
            console.log(this.clientProviderTypeMean)
            if(this.propForm.certificateType==0){
                this.certificateTypeMean='营业执照'
            }else if(this.propForm.certificateType==1){
                this.certificateTypeMean='组织机构代码证'
            }else if(this.propForm.certificateType==2){
                this.certificateTypeMean='社会信用码'
            }else if(this.propForm.certificateType==3){
                this.certificateTypeMean='税务登记号'
            }else if(this.propForm.certificateType==4){
                this.certificateTypeMean='其他'
            }
            loading.close()
        }).catch(e => {
            loading.close()
            this.$message({
                type: 'error',
                message: '数据获取失败!'
            })
        })

        this.queryLinkInfo(this.supplierId);

    },
    mounted(){
        this.queryItem()
    },
    data() {
        return {
            supplierId: '',
            streets: [],
            propForm: {
                clientProviderName:'',
                clientProviderType:'',
                certificateType:'',
                certificateNum:'',
                scopeBusiness:'',
                address:'',
                providerPrincipal:'',
                phoneNum:'',
                email:'',
                remarks:''
            },
            clientProviderTypeMean:'',
            certificateTypeMean:'',
            linkInfo:[],
            searchForm:{},
            modelType: 'supplierManage',
            uploadFileList:'',
            busId:'',
            activeName: 'first',
            //合同信息
            contractData:[],
            projectData:[],
        }
    },
    methods: {
        queryItem(val){
            this.$refs.providerUpload.getFiles(this.supplierId);
        },
        queryLinkInfo(val){
            this.searchForm.supplierId=this.supplierId;
            // getObjOne(this.supplierId).then(response=>{
            //     this.linkInfo=response.data.data
            // }).catch(()=>{
            //     console.log("catch")
            // })
            getByclientProviderId(this.supplierId).then(respdata=>{

                let data = respdata.data.data.clientProviderLinkinfos.map((item, index) => ({...item, index}))
                this.linkInfo = [...data]
            })
        },
        closeTab() {
            //关闭当前新增页，暂时没找到好办法
           // this.$store.commit("delHistoryRoute", this.$route.fullPath);
            // this.$parent.$children[2].closeTab('current')
            //跳转
            //this.$router.push("/property-info-sys/project-manage");
        },
        searchByKey(){},
        searchReset(){},
        selectionChange(){},
        changePageSize(){},
        changeCurrentPage(){},

    }

}
